/******************************************************************************
 * FileName:    gwin_fifo.c
 * Desc:        fifo
 *
 *
 * Author:      Lin
 * Notes:
 *
 ******************************************************************************/

#ifndef __GWIN_FIFO_H__
#define __GWIN_FIFO_H__


/*-------------------------- Includes ---------------------------------------*/
#include <stdint.h>
#include <stdlib.h>


/*-------------------------- Macro Definitions ------------------------------*/

/*-------------------------- Type Declarations ------------------------------*/
typedef struct
{
    uint8_t *buf;                   // 缓存
    uint16_t size_mask;             // 缓存大小 注意：2的整数倍
    volatile uint16_t read_pos;     // 读位置
    volatile uint16_t write_pos;    // 写位置
}gwin_fifo_t;


/*-------------------------- Global Variables -------------------------------*/

/*-------------------------- Local Variables --------------------------------*/

/*-------------------------- Functions Declarations -------------------------*/

/*-------------------------- Functions Definitions --------------------------*/
uint8_t gwin_fifo_init(gwin_fifo_t *fifo, uint8_t *buf, uint16_t len);

void gwin_fifo_flush(gwin_fifo_t *fifo);
uint16_t gwin_fifo_length(gwin_fifo_t *fifo);
uint16_t gwin_fifo_remain(gwin_fifo_t *fifo);
uint8_t *gwin_fifo_get_write_pos(gwin_fifo_t *fifo);

uint16_t gwin_fifo_read(gwin_fifo_t *fifo, uint8_t *data, uint16_t len);
uint16_t gwin_fifo_write(gwin_fifo_t *fifo, const uint8_t *data, uint16_t len);


#endif // __GWIN_FIFO_H__


/*-------------------------- END OF FILE ------------------------------------*/

